package com.strutor.likou.ltree;

public class Solution {
    //判断两个树是否相等
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return isSameNode(p, q);
    }

    private boolean isSameNode(TreeNode p, TreeNode q) {
        if (p == null && q ==null){
            return true;
        }
        if (p == null || q ==null){
            return false;
        }
        if (p.val == q.val){
            return isSameNode(p.left,q.left) && isSameNode(p.right,q.right);
        }
        return false;
    }


    //判断两个树是否是镜像对称树
    public boolean isSymmetric(TreeNode root) {
        if (root == null){
            return false;
        }
        return isSymmetricNode(root.left,root.right);
    }

    private boolean isSymmetricNode(TreeNode left, TreeNode right) {
        if (left == null && right ==null){
            return true;
        }
        if (left == null || right ==null){
            return false;
        }
        if (left.val != right.val){
            return false;
        }
        return isSymmetricNode(left.right,right.left) && isSymmetricNode(left.left,right.right);
    }

    public static void main(String[] args) {

    }
}
